package com.laoxu.game.view;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @description: 五子棋主界面
 * @author: luohanye
 * @create: 2019-03-21
 **/
public class MyFrame extends JFrame implements MouseListener {
    public MyFrame() {
        int width=800,height=600;
        //窗体标题
        this.setTitle("冒险岛游戏");

        //窗体大小
        this.setSize(width, height);
        //获取当前平面分辨率，例如：1920x1080
        int swidth = Toolkit.getDefaultToolkit().getScreenSize().width;
        int sheight = Toolkit.getDefaultToolkit().getScreenSize().height;
        System.out.println("width=" + swidth + " height=" + sheight);
        //设置窗体出现的位置
        this.setLocation((swidth - width) / 2, (sheight - height) / 2);
        //点击关闭退出程序
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.addMouseListener(this);
        //窗体可见
        this.setVisible(true);

    }

    public void paint(Graphics g){
        //绘制字符串
//        g.drawString("五子棋游戏",20,40);
        //绘制空心圆
//        g.drawOval(20,40,40,40);
        //绘制实心圆
//        g.fillOval(20,40,40,40);
        //绘制一条线
//        g.drawLine(20,40,80,40);
        //绘制一个空心矩形
//        g.drawRect(20,40,40,20);
        //绘制一个实心矩形
//        g.fillRect(80,40,40,20);
        BufferedImage image = null;
        try {
             image = ImageIO.read(new File("E:/java/视频教程/单机版五子棋/游戏运行文件/image/background.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        g.drawImage(image,10,10,this);
    }

    //鼠标按键在组件上单击（按下并释放）时调用。
    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    //鼠标按键在组件上按下时调用。
    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("X="+e.getX()+" Y="+e.getY());
    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
